﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media.Animation;
using System.Windows.Media.Media3D;
using System.Threading;

namespace mat2tab_fun
{
    public partial class StereometryPage : Page
    {
        Point3D sr = new Point3D(50, 0, 50);
        RotateTransform3D myRotateTransform3D;
        AxisAngleRotation3D myAxisAngleRotation3d = new AxisAngleRotation3D();
        Transform3DGroup myTransform3DGroup = new Transform3DGroup();

        RotateTransform3D myRotateTransform3D2;
        AxisAngleRotation3D myAxisAngleRotation3d2 = new AxisAngleRotation3D();
        Transform3DGroup myTransform3DGroup2 = new Transform3DGroup();

        public StereometryPage()
        {
            InitializeComponent();

            myAxisAngleRotation3d.Axis = new Vector3D(0, 1, 0);
            myAxisAngleRotation3d.Angle = -5;

            myRotateTransform3D = new RotateTransform3D(myAxisAngleRotation3d, sr);

            myAxisAngleRotation3d2.Axis = new Vector3D(1, 0, 0);
            myAxisAngleRotation3d2.Angle = -5;
           
            myRotateTransform3D2 = new RotateTransform3D(myAxisAngleRotation3d2, new Point3D(0,50,50));
            
            myTransform3DGroup.Children.Add(myRotateTransform3D);
            myTransform3DGroup2.Children.Add(myRotateTransform3D2);
        }

        private void backButton_Click(object sender, RoutedEventArgs e)
        {
            Switcher.Switch(new Menu());
        }

        private void rotateX_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            myAxisAngleRotation3d.Angle = e.NewValue;
            foreach(ModelVisual3D m in viewport3D.Children)
            {
                if(m != lampa)
                    m.Transform = myTransform3DGroup;
            }
        }

        private void rotateY_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            myAxisAngleRotation3d2.Angle = e.NewValue;
            foreach (ModelVisual3D m in viewport3D.Children)
            {
                if (m != lampa)
                m.Transform = myTransform3DGroup2;
            }
        }


        private void button1_Click(object sender, RoutedEventArgs e)
        {
            Point3D camPos = camera.Position;

            myTransform3DGroup.Children.Clear();
            camPos.X = 130;
            sr.X = 50;
            myRotateTransform3D = new RotateTransform3D(myAxisAngleRotation3d, sr);
            myTransform3DGroup.Children.Add(myRotateTransform3D);
            foreach (ModelVisual3D m in viewport3D.Children)
            {
                if (m != lampa)
                    m.Transform = myTransform3DGroup;
            }
            camera.Position = camPos;
            info.Content = "Sześcian";
            image2.Visibility = System.Windows.Visibility.Hidden;
            image3.Visibility = System.Windows.Visibility.Hidden;
            image4.Visibility = System.Windows.Visibility.Hidden;
            image1.Visibility = System.Windows.Visibility.Visible;

            button1.BorderBrush = Brushes.Red;
            button2.BorderBrush = Brushes.Black;
            button3.BorderBrush = Brushes.Black;
            button4.BorderBrush = Brushes.Black;
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            Point3D camPos = camera.Position;

            myTransform3DGroup.Children.Clear();
            camPos.X = 10130;
            sr.X = 10050;
            myRotateTransform3D = new RotateTransform3D(myAxisAngleRotation3d, sr);
            myTransform3DGroup.Children.Add(myRotateTransform3D);
            foreach (ModelVisual3D m in viewport3D.Children)
            {
                if (m != lampa)
                    m.Transform = myTransform3DGroup;
            }
            camera.Position = camPos;
            info.Content = "Ostrosłup trójkątny";
            image2.Visibility = System.Windows.Visibility.Visible;
            image3.Visibility = System.Windows.Visibility.Hidden;
            image4.Visibility = System.Windows.Visibility.Hidden;
            image1.Visibility = System.Windows.Visibility.Hidden;
            button1.BorderBrush = Brushes.Black;
            button2.BorderBrush = Brushes.Red;
            button3.BorderBrush = Brushes.Black;
            button4.BorderBrush = Brushes.Black;
        }

        private void button3_Click(object sender, RoutedEventArgs e)
        {
            Point3D camPos = camera.Position;

            myTransform3DGroup.Children.Clear();
            camPos.X = 20130;
            sr.X = 20050;
            myRotateTransform3D = new RotateTransform3D(myAxisAngleRotation3d, sr);
            myTransform3DGroup.Children.Add(myRotateTransform3D);
            foreach (ModelVisual3D m in viewport3D.Children)
            {
                if (m != lampa)
                    m.Transform = myTransform3DGroup;
            }
            camera.Position = camPos;
            info.Content = "Walec";
            image2.Visibility = System.Windows.Visibility.Hidden;
            image3.Visibility = System.Windows.Visibility.Visible;
            image4.Visibility = System.Windows.Visibility.Hidden;
            image1.Visibility = System.Windows.Visibility.Hidden;
            button1.BorderBrush = Brushes.Black;
            button2.BorderBrush = Brushes.Black;
            button3.BorderBrush = Brushes.Red;
            button4.BorderBrush = Brushes.Black;
        }

        private void button4_Click(object sender, RoutedEventArgs e)
        {
            Point3D camPos = camera.Position;

            myTransform3DGroup.Children.Clear();
            camPos.X = 30130;
            sr.X = 30050;
            myRotateTransform3D = new RotateTransform3D(myAxisAngleRotation3d, sr);
            myTransform3DGroup.Children.Add(myRotateTransform3D);
            foreach (ModelVisual3D m in viewport3D.Children)
            {
                if (m != lampa)
                    m.Transform = myTransform3DGroup;
            }
            camera.Position = camPos;
            info.Content = "Stożek";
            image2.Visibility = System.Windows.Visibility.Hidden;
            image3.Visibility = System.Windows.Visibility.Hidden;
            image4.Visibility = System.Windows.Visibility.Visible;
            image1.Visibility = System.Windows.Visibility.Hidden;
            button1.BorderBrush = Brushes.Black;
            button2.BorderBrush = Brushes.Black;
            button3.BorderBrush = Brushes.Black;
            button4.BorderBrush = Brushes.Red;
        }

        private void Page_Loaded(object sender, RoutedEventArgs e)
        {

        }
    }
}
